﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class add_column_appmodule_Descr : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainAppTopic_MainAppModule_AppModuleId",
                table: "MainAppTopic");

            migrationBuilder.DropForeignKey(
                name: "FK_MainAppTopic_OpenIddictApplications_OpenIddictApplicationId",
                table: "MainAppTopic");

            migrationBuilder.DropIndex(
                name: "IX_MainAppTopic_OpenIddictApplicationId",
                table: "MainAppTopic");

            migrationBuilder.DropColumn(
                name: "OpenIddictApplicationId",
                table: "MainAppTopic");

            migrationBuilder.RenameColumn(
                name: "OpenApiConfigId",
                table: "MainDataFormDict",
                newName: "OpenApiDictId");

            migrationBuilder.RenameColumn(
                name: "Exp",
                table: "MainAppTopic",
                newName: "Descr");

            migrationBuilder.RenameColumn(
                name: "Exp",
                table: "MainAppModule",
                newName: "Descr");

            migrationBuilder.AlterColumn<Guid>(
                name: "AppModuleId",
                table: "MainAppTopic",
                type: "uuid",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
                oldClrType: typeof(Guid),
                oldType: "uuid",
                oldNullable: true);

            migrationBuilder.AddColumn<DateTime>(
                name: "CreationTime",
                table: "MainAppTopic",
                type: "timestamp with time zone",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

            migrationBuilder.AddColumn<Guid>(
                name: "CreatorId",
                table: "MainAppTopic",
                type: "uuid",
                nullable: true);

            migrationBuilder.AddColumn<DateTime>(
                name: "LastModificationTime",
                table: "MainAppTopic",
                type: "timestamp with time zone",
                nullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "LastModifierId",
                table: "MainAppTopic",
                type: "uuid",
                nullable: true);

            migrationBuilder.AddForeignKey(
                name: "FK_MainAppTopic_MainAppModule_AppModuleId",
                table: "MainAppTopic",
                column: "AppModuleId",
                principalTable: "MainAppModule",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainAppTopic_MainAppModule_AppModuleId",
                table: "MainAppTopic");

            migrationBuilder.DropColumn(
                name: "CreationTime",
                table: "MainAppTopic");

            migrationBuilder.DropColumn(
                name: "CreatorId",
                table: "MainAppTopic");

            migrationBuilder.DropColumn(
                name: "LastModificationTime",
                table: "MainAppTopic");

            migrationBuilder.DropColumn(
                name: "LastModifierId",
                table: "MainAppTopic");

            migrationBuilder.RenameColumn(
                name: "OpenApiDictId",
                table: "MainDataFormDict",
                newName: "OpenApiConfigId");

            migrationBuilder.RenameColumn(
                name: "Descr",
                table: "MainAppTopic",
                newName: "Exp");

            migrationBuilder.RenameColumn(
                name: "Descr",
                table: "MainAppModule",
                newName: "Exp");

            migrationBuilder.AlterColumn<Guid>(
                name: "AppModuleId",
                table: "MainAppTopic",
                type: "uuid",
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uuid");

            migrationBuilder.AddColumn<Guid>(
                name: "OpenIddictApplicationId",
                table: "MainAppTopic",
                type: "uuid",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

            migrationBuilder.CreateIndex(
                name: "IX_MainAppTopic_OpenIddictApplicationId",
                table: "MainAppTopic",
                column: "OpenIddictApplicationId");

            migrationBuilder.AddForeignKey(
                name: "FK_MainAppTopic_MainAppModule_AppModuleId",
                table: "MainAppTopic",
                column: "AppModuleId",
                principalTable: "MainAppModule",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_MainAppTopic_OpenIddictApplications_OpenIddictApplicationId",
                table: "MainAppTopic",
                column: "OpenIddictApplicationId",
                principalTable: "OpenIddictApplications",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
